package com.didispace.chapter310.service;

import com.didispace.chapter310.Test2;
import com.didispace.chapter310.User;
import com.didispace.chapter310.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class Test2Impl implements Test2 {
    @Autowired
    private UserRepository userRepository;
    @Override
    @Transactional(rollbackFor = RuntimeException.class,readOnly = false,value="transactionManager",propagation= Propagation.REQUIRES_NEW)
    public void test21() {
        User a = new User("HHHH222222", 10);
        System.out.println(a.getName());
        System.out.println(a.getName().length());
        userRepository.save(a);
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class,readOnly = false,value="transactionManager",propagation= Propagation.REQUIRED)
    public void test22() {
        User a = new User("REQUIRED", 10);
        System.out.println(a.getName());
        System.out.println(a.getName().length());
        userRepository.save(a);
    }
}
